package com.ruoyi.web.controller.qsng;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.qsng.service.ITMessagePushService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.TMessagePush;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 消息推送Controller
 * 
 * @author gk
 * @date 2023-08-14
 */
@RestController
@RequestMapping("/system/push")
public class TMessagePushController extends BaseController
{
    @Autowired
    private ITMessagePushService tMessagePushService;

    /**
     * 查询消息推送列表
     */
    @PreAuthorize("@ss.hasPermi('system:push:list')")
    @GetMapping("/list")
    public TableDataInfo list(TMessagePush tMessagePush)
    {
        startPage();
        List<TMessagePush> list = tMessagePushService.selectTMessagePushList(tMessagePush);
        return getDataTable(list);
    }

    /**
     * 导出消息推送列表
     */
    @PreAuthorize("@ss.hasPermi('system:push:export')")
    @Log(title = "消息推送", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TMessagePush tMessagePush)
    {
        List<TMessagePush> list = tMessagePushService.selectTMessagePushList(tMessagePush);
        ExcelUtil<TMessagePush> util = new ExcelUtil<TMessagePush>(TMessagePush.class);
        util.exportExcel(response, list, "消息推送数据");
    }

    /**
     * 获取消息推送详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:push:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(tMessagePushService.selectTMessagePushById(id));
    }

    /**
     * 新增消息推送
     */
    @PreAuthorize("@ss.hasPermi('system:push:add')")
    @Log(title = "消息推送", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TMessagePush tMessagePush)
    {
        return toAjax(tMessagePushService.insertTMessagePush(tMessagePush));
    }

    /**
     * 修改消息推送
     */
    @PreAuthorize("@ss.hasPermi('system:push:edit')")
    @Log(title = "消息推送", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TMessagePush tMessagePush)
    {
        return toAjax(tMessagePushService.updateTMessagePush(tMessagePush));
    }

    /**
     * 删除消息推送
     */
    @PreAuthorize("@ss.hasPermi('system:push:remove')")
    @Log(title = "消息推送", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(tMessagePushService.deleteTMessagePushByIds(ids));
    }
}
